<?php
if(function_exists('date_default_timezone_set'))
   date_default_timezone_set("Asia/Ho_Chi_Minh");
else
   putenv("TZ=Asia/Ho_Chi_Minh");
function random_str($len = 5) {
	$s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
	mt_srand ((double)microtime() * 1000000);
	$unique_id = '';
	for ($i=0;$i< $len;$i++)
		$unique_id .= substr($s, (mt_rand()%(strlen($s))), 1);
	return $unique_id;
}
function curl_cook($url){
 $agents[] = "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.18) Gecko/20081203 Firefox/2.0.0.18";
 $agents[] = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16";
 $agents[] = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1";
	 $ch=curl_init();
	 curl_setopt ($ch, CURLOPT_URL, $url); 
     curl_setopt ($ch, CURLOPT_USERAGENT, $agents[rand(0,(count($agents)-1))]); 
	 curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
     curl_setopt ($ch, CURLOPT_COOKIEJAR, "cbi-bin.txt");
	 curl_setopt($ch, CURLOPT_COOKIEFILE, "cbi-bin.txt");
	 curl_setopt($ch, CURLOPT_REFERER, "http://www.youtube.com/");
     curl_setopt ($ch, CURLOPT_HEADER, 1); 
     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
    // curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
     $result = curl_exec ($ch);
     curl_close($ch);
	 return	$result;
}
$ht=date("dth");
$id=$_GET['id'];
$idde=base64_decode($id);
$idded=str_replace($ht,'',$idde);

$data=curl_cook('http://www.youtube.com/view_play_list?p='.$idded);

//preg_match_all('#watch\?v=(.*?)&#', $data, $t_mat);
preg_match_all('#a id="video-long-title-(.*?)"#', $data, $t_mat);
header("Content-Type: application/xml; charset=utf-8");
$xml = '<?xml version="1.0" encoding="utf-8"?>'.
	'<playlist version="1" xmlns="http://xspf.org/ns/0/">'.
	'<trackList>';
for($i=0;$i<=count($t_mat[0])-1;$i++){
$a=random_str(3);
$b=random_str(2);
$c=random_str(1);
$vlt=substr($t_mat[1][$i],0,-1);
$nkute=substr($t_mat[1][$i],10);
$iden=$a.$vlt.$b.$nkute.$c;
 $arr_host=array("http://grab.haiduongvui.com/","http://yeuhaiduong.com");
$id_host=rand(0,count($arr_host)-1);
$xml .= '<track>
<title>360Do.cc Part '.$i.$lol.'</title>
<meta rel="captions">none</meta>
<location>'.$arr_host[$id_host].'/pyoutube.php?id='.base64_encode($iden).'</location>
<meta rel="type">video</meta>
</track>';
}
$xml .= '</trackList>'.
	'</playlist>';
echo $xml;
?>